#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
using namespace std;
class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums)
    {
        vector<int> L;
        int pro = 1;
        for (int i = 0;i < nums.size();++i)
        {
            pro *= nums[i];
            L.push_back(pro);
        }
        vector<int> R(nums.size(), 0);
        pro = 1;
        for (int i = nums.size() - 1;i >= 0;--i)
        {
            pro *= nums[i];
            R[i] = pro;
        }
        vector<int> ret(nums.size(), 0);
        ret[0] = R[1];
        ret[nums.size() - 1] = L[nums.size() - 2];
        for (int i = 1;i < nums.size() - 1;++i)
        {
            ret[i] = L[i - 1] * R[i + 1];
        }
        return ret;
    }
};